package com.example.studyPlatform.Filter;

import com.example.studyPlatform.bean.User;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

import static com.example.studyPlatform.config.BaseConstant.*;
import static com.example.studyPlatform.config.RoutingConstant.LOGIN;
import static com.example.studyPlatform.controller.api.kit.UrlUtils.normUrl;

@WebFilter(filterName = "jsessionidFilter", urlPatterns = "/*")
public class JsessionidFilter implements Filter {
    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest httpRequest = (HttpServletRequest) req;
        String url = httpRequest.getRequestURI();
        //消除jsessionid影响
        String url2 = url.replaceFirst(";jsessionid=.+$", "");
        if (url.length() != url2.length()){
            ((HttpServletResponse)resp).sendRedirect(url2);
        }else {
            chain.doFilter(req, resp);
        }
    }
}
